package main

import (
	"encoding/base64"
	"fmt"
)

func main(){
	//base64的加密解密
	//因为会涉及到取模等等的操作，因此会对“/”造成错误
	msg:="hello,世界"
	encoded:=base64.StdEncoding.EncodeToString([]byte(msg))
	fmt.Println(encoded)
	decoded,err:=base64.StdEncoding.DecodeString(encoded)
	if err!=nil{
		panic(err)
	}
	fmt.Println(string(decoded))

	//因此，使用URLEncoding将会避免这种情况
	encoded=base64.URLEncoding.EncodeToString([]byte(msg))
	fmt.Printf("%T,%s\n",encoded,encoded)
	decoded,err=base64.URLEncoding.DecodeString(encoded)
	if err!=nil{
		panic(err)
	}
	fmt.Printf("%T,%s\n",decoded,string(decoded))
}
